﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WLCompiler.Helpers
{
    internal class LogStringWriterDecorator : System.IO.StringWriter
    {
        protected readonly Common.Logging.ILog Logger;

        public LogStringWriterDecorator(Common.Logging.ILog logger)
        {
            Logger = logger;
            
            EnableLogSource = false;
        }

        public bool EnableLogSource { get; set; }

        public System.IO.TextReader SourceCode { get; set; }

        public void TraceLog()
        {
            if (EnableLogSource)
            {
                Logger.Info(Environment.NewLine + SourceCode.ReadToEnd());      
            }

            if (ToString() != string.Empty)
            {
                Logger.Error(ToString());
                Console.WriteLine(ToString());
            }
            else
            {
                Logger.Info("Build Success.");
            }
        }
    }
}
